import { NodeValidateRule } from '@/ts/base/model';
import { NodeRef } from '../ref/refs';
import { GraphNodeBase } from './GraphNodeBase';
import { XCells, XFloatRowsInfo, XRowsInfo } from '@/ts/base/schema';
import { RefGraph } from '..';
import RefParser from '../ref/RefParser';

export default class FloatColumnValidateRuleNode extends GraphNodeBase<'float-column-validate'> {
  // 计算规则本身没有编码
  get name() {
    return this.rule.id;
  }
  get label() {
    return `[浮动行校验 ${this.floatRow.floatRowCode} ${this.column.name}列]` + this.rule.name;
  }

  refs: NodeRef[] = [];
  sheet: string;

  value: any;

  readonly rule: NodeValidateRule;
  readonly column: XRowsInfo;
  readonly floatRow: XFloatRowsInfo;
  constructor(
    rule: NodeValidateRule,
    column: XRowsInfo,
    floatRow: XFloatRowsInfo,
    graph: RefGraph,
    sheet: string,
    formId: string,
  ) {   
    super('float-column-validate');
    this.rule = rule;
    this.column = column;
    this.floatRow = floatRow;
    this.sheet = sheet;
    this.formId = formId;

    this.parseRef(graph);
  }

  protected parseRef(graph: RefGraph) {
    const refs = RefParser.columnRefs(this.rule.formula);
    for (const ref of refs.columns) {
      this.refs.push({
        type: 'report-float-column',
        name: `${this.floatRow.floatRowCode}$${ref}-inline`,
        formId: this.formId,
        sheet: this.sheet,
        floatRow: this.floatRow.floatRowCode,
        column: ref,
        inline: true,
      });
    }
  }

}
